package com.zhiche.lisa.mdm.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zhiche.lisa.mdm.dao.mapper.TransportationTypeMapper;
import com.zhiche.lisa.mdm.dao.model.ServiceType;
import com.zhiche.lisa.mdm.dao.model.TransportationType;
import com.zhiche.lisa.mdm.service.IServiceTypeService;
import com.zhiche.lisa.mdm.service.ITransportationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 运输工具类型 服务实现类
 * </p>
 *
 * @author qichao
 * @since 2018-06-18
 */
@Service
public class TransportationTypeServiceImpl extends ServiceImpl<TransportationTypeMapper, TransportationType> implements ITransportationTypeService {
    @Autowired
    private IServiceTypeService serviceTypeService;

    @Override
    public List<TransportationType> getTransportType(String tosType) {
        EntityWrapper<TransportationType> ew = new EntityWrapper<>();
        ew.eq("tos_code", tosType);
        return this.selectList(ew);
    }

    @Override
    public List<TransportationType> getAllTransportType() {
        return this.selectList(new EntityWrapper<>());
    }

    @Override
    public TransportationType getTransportTypeById(Integer transportTypeId) {
        return this.selectById(transportTypeId);
    }

    @Override
    public TransportationType getTransportTypeByCode(String transportTypeCode) {
        EntityWrapper<TransportationType> ew = new EntityWrapper<>();
        ew.eq("code", transportTypeCode);
        return this.selectOne(ew);
    }

    /**
     * 根据tosCode对应的ServiceTypeId查询所有匹配的乐星
     * @param typeId
     * @return
     */
    @Override
    public List<TransportationType> getTransportTypeByServiceTypeId(Long typeId) {
        ServiceType serviceType = serviceTypeService.selectById(typeId);
        if (serviceType != null) {
            EntityWrapper<TransportationType> ew = new EntityWrapper<>();
            ew.eq("tos_code", serviceType.getCode());
            return selectList(ew);
        }
        return null;
    }
}
